<template>
	<view class="container">
		<view class="form-section">
			<text class="section-title">{{ isEditMode ? '编辑试卷内容' : '试卷上传' }}</text>
			<text class="section-desc">{{ isEditMode ? '请修改以下信息，更新考试试卷内容' : '请填写以下信息，创建新的考试试卷' }}</text>
			
			<view class="form-item">
				<text class="form-label required">试卷标题</text>
				<input class="form-input" type="text" v-model="formData.title" placeholder="请输入试卷标题" />
			</view>
			
			<view class="form-item">
				<text class="form-label required">试卷描述</text>
				<view class="textarea-container">
					<textarea class="form-textarea" v-model="formData.description" placeholder="请输入试卷描述，包括考试目的、适用人群等" />
				</view>
			</view>
			
			<view class="form-item">
				<text class="form-label required">试卷类型</text>
				<picker class="form-picker" :value="examTypeIndex" :range="examTypeOptions" @change="bindExamTypeChange">
					<view class="picker-value">
						{{ examTypeOptions[examTypeIndex] }}
					</view>
				</picker>
			</view>
			
			<view class="form-item">
				<text class="form-label required">考试时间(分钟)</text>
				<input class="form-input" type="number" v-model="formData.time_limit" placeholder="请输入考试时间限制，单位：分钟" />
			</view>
			
			<view class="form-item">
				<text class="form-label required">总分</text>
				<input class="form-input" type="number" v-model="formData.total_score" placeholder="请输入试卷总分" />
			</view>
			
			<view class="form-item">
				<text class="form-label required">及格分数</text>
				<input class="form-input" type="number" v-model="formData.pass_score" placeholder="请输入及格分数" />
			</view>
			
			
			<!-- 题目列表 -->
			<view class="questions-section">
				<view class="section-header">
					<text class="section-title">试题管理</text>
					<!-- 添加题目按钮 -->
					<view class="add-question-btn" @click="navigateToQuestionEdit">
						<view class="plus-icon">+</view>
						<text>添加题目</text>
					</view>
				</view>
				
				<view class="empty-tip" v-if="formData.questions.length === 0">
					<text class="empty-text">暂无试题，请点击"添加题目"按钮添加</text>
				</view>
				
				<view class="question-list" v-else>
					<view class="question-item" v-for="(question, index) in formData.questions" :key="index">
						<view class="question-header">
							<text class="question-number">{{index+1}}</text>
							<text class="question-type">[{{getQuestionTypeName(question.type)}}]</text>
							<text class="question-score">{{question.score}}分</text>
						</view>
						<view class="question-title" @click="editQuestion(index)">{{question.title}}</view>
						
						<!-- 媒体文件显示区 -->
						<view class="question-media" v-if="question.media_files && question.media_files.length > 0">
							<view v-for="(media, mediaIndex) in question.media_files" :key="mediaIndex" class="media-preview">
								<image v-if="media.type === 'image'" :src="media.url" mode="aspectFit" class="media-image" @click="previewMedia(media)"></image>
								<video v-if="media.type === 'video'" :src="media.url" controls class="media-video" object-fit="contain" show-fullscreen-btn="true" enable-play-gesture="true" show-play-btn="true" initial-time="0" @error="handleVideoError"></video>
							</view>
						</view>
						
						<!-- 单选题和多选题选项 -->
						<view class="question-options" v-if="question.type !== 'judge'">
							<view class="option-item" v-for="(option, optionIndex) in question.options" :key="optionIndex">
								<text class="option-letter">{{String.fromCharCode(65 + optionIndex)}}</text>
								<text class="option-content">{{option.content}}</text>
								<text v-if="question.type === 'single' && question.correct_option === optionIndex" class="option-correct">✓</text>
								<text v-if="question.type === 'multiple' && question.correct_options.includes(optionIndex)" class="option-correct">✓</text>
							</view>
						</view>
						
						<!-- 判断题答案 -->
						<view class="question-judge" v-if="question.type === 'judge'">
							<text class="judge-answer">正确答案: {{question.correct_option ? '正确' : '错误'}}</text>
						</view>
						
						<view class="question-actions">
							<view class="action-btn delete-btn" @click="deleteQuestion(index)">删除</view>
							<view class="action-btn edit-btn" @click="editQuestion(index)">编辑</view>
						</view>
					</view>
				</view>
			</view>
			
		</view>
		
		<view class="submit-section">
			<button class="submit-btn" @click="submitForm" :disabled="submitting">
				{{ submitting ? (isEditMode ? '更新中...' : '提交中...') : (isEditMode ? '更新试卷' : '提交') }}
			</button>
		</view>
	</view>
</template>

<script>
	import '@/packageadmin/admin/app.css';
	
	export default {
		components: {
		},
		data() {
			return {
				examId: '', // 添加考试ID字段
				isEditMode: false, // 添加编辑模式标记
				formData: {
					title: '',
					description: '',
					exam_type: 'knowledge', // 默认为知识测试
					time_limit: 60,
					total_score: 100,
					pass_score: 60,
					cover_image: '',
					questions: [],
					media_files: [] // 添加整个试卷的顶层media_files字段
				},
				examTypeIndex: 0,
				// 修改试卷类型选项
				examTypeOptions: ['知识测试', '练习题', '竞赛题', '认证考试', '其他'],
				// 添加试卷类型映射
				examTypeValues: ['knowledge', 'practice', 'competition', 'certification', 'other'],
				uploadStatus: {
					cover: false,
					questionMedia: false
				},
				submitting: false,
			}
		},
		onLoad(options) {
			console.log('考试上传页面onLoad, 参数:', options);
			
			// 获取并验证ID参数
			let examId = '';
			if (options && options.id) {
				examId = decodeURIComponent(options.id);
				console.log('从URL参数获取考试ID:', examId);
			}
			
			// 如果URL参数中没有ID，尝试从本地存储获取
			if (!examId) {
				try {
					const storedId = uni.getStorageSync('edit_exam_id');
					if (storedId) {
						examId = storedId;
						console.log('从本地存储获取考试ID:', examId);
					}
				} catch (error) {
					console.error('读取本地存储ID失败:', error);
				}
			}
			
			// 检查ID是否有效
			if (examId && options.mode === 'edit') {
				this.examId = examId;
				this.isEditMode = true;
				console.log('设置编辑模式, 考试ID:', this.examId);
			} else if (options.mode === 'edit') {
				// 模式为编辑但没有ID
				console.error('编辑模式但ID无效');
				uni.showToast({
					title: '考试ID无效，无法编辑',
					icon: 'none',
					duration: 2000
				});
				setTimeout(() => {
					uni.navigateBack();
				}, 1500);
				return;
			}
			
			// 检查用户权限
			this.checkadminPermission();
			
			// 如果是编辑模式且ID有效，加载考试详情
			if (this.isEditMode && this.examId) {
				console.log('准备加载考试详情');
				// 延迟加载详情，确保页面已经完全初始化
				setTimeout(() => {
					this.loadExamDetail();
				}, 300);
			}
		},
		methods: {
			// 检查是否为裁判监督并已认证
			checkadminPermission() {
				try {
					// 尝试获取用户信息
					let userInfo = {};
					const userInfoStr = uni.getStorageSync('userInfo');
					
					// 尝试解析本地存储的用户信息
					if (userInfoStr) {
						try {
							userInfo = JSON.parse(userInfoStr);
						} catch (e) {
							userInfo = userInfoStr; // 如果已经是对象，直接使用
						}
					} else {
						userInfo = {}; // 无数据
					}
					
					// 当userId存在但_id不存在时，或相反情况，互相赋值以保证兼容性
					if (userInfo.userId && !userInfo._id) userInfo._id = userInfo.userId;
					if (userInfo._id && !userInfo.userId) userInfo.userId = userInfo._id;
					
					// 检查用户ID和角色
					const hasValidId = userInfo._id || userInfo.userId;
					const isadmin = userInfo.role === 4 || userInfo.role === "4" || userInfo.role === "admin" || userInfo.role === "管理员";
					
					// 检查证书状态 - 扩展判断条件，增加更多可能的有效值
					const credentialStatus = String(userInfo.credential_status || '').toLowerCase();
					const status = String(userInfo.status || '').toLowerCase();
					
					const validStatusValues = ['approved', 'valid', 'verified', 'active', '有效', '通过', '已认证', '已通过'];
					const hasValidCredential = validStatusValues.some(value => 
						credentialStatus.includes(value) || status.includes(value)
					);
					
					// 为调试目的，输出详细的验证信息
					console.log('权限验证信息：', {
						hasValidId,
						isadmin,
						hasValidCredential,
						credentialStatus,
						status,
						userInfo 
					});
					
					// 如果不满足条件，显示错误
					if (!hasValidId || !isadmin || !hasValidCredential) {
						console.error('权限验证失败：', {
							hasValidId,
							isadmin,
							hasValidCredential,
							userInfo 
						});
						
						uni.showModal({
							title: '无权访问',
							content: '该页面仅对认证通过的裁判监督开放',
							showCancel: false,
							success: () => {
								uni.navigateBack();
							}
						});
						return false;
					}
					
					return true;
				} catch (error) {
					console.error('权限检查失败:', error);
					uni.showModal({
						title: '系统错误',
						content: '权限验证失败，请重新登录后再试',
						showCancel: false,
						success: () => {
							uni.navigateBack();
						}
					});
					return false;
				}
			},
			
			// 修改试卷类型选择处理方法
			bindExamTypeChange(e) {
				this.examTypeIndex = e.detail.value;
				this.formData.exam_type = this.examTypeValues[this.examTypeIndex];
			},
			
			// 在加载试卷详情时设置正确的类型索引
			setExamTypeIndex(type) {
				const index = this.examTypeValues.indexOf(type);
				this.examTypeIndex = index >= 0 ? index : 0;
			},
			
			// 选择封面图片
			chooseImage() {
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'],
					success: (res) => {
						this.formData.cover_image = res.tempFilePaths[0];
						this.uploadStatus.cover = false;
					}
				});
			},
			
			// 删除封面图片
			removeImage() {
				this.formData.cover_image = '';
				this.uploadStatus.cover = false;
			},
			
			// 上传封面图片
			uploadCoverImage() {
				return new Promise((resolve, reject) => {
					if (!this.formData.cover_image) {
						resolve('');
						return;
					}
					
					if (this.uploadStatus.cover) {
						resolve(this.formData.cover_image);
						return;
					}
					
					const filePath = this.formData.cover_image;
					const cloudPath = `exams/covers/${new Date().getTime()}_cover.jpg`;
					
					uni.showLoading({ title: '封面上传中...' });
					
					uniCloud.uploadFile({
						filePath: filePath,
						cloudPath: cloudPath,
						success: (res) => {
							this.formData.cover_image = res.fileID;
							this.uploadStatus.cover = true;
							resolve(res.fileID);
						},
						fail: (err) => {
							console.error('封面上传失败', err);
							reject(err);
						},
						complete: () => {
							uni.hideLoading();
						}
					});
				});
			},
			
			// 删除题目
			deleteQuestion(index) {
				uni.showModal({
					title: '确认删除',
					content: '确定要删除这道题目吗？',
					success: (res) => {
						if (res.confirm) {
							this.formData.questions.splice(index, 1);
							this.showToast('删除成功');
							this.updateTotalScore();
						}
					}
				});
			},
			
			// 更新总分
			updateTotalScore() {
				if (this.formData.questions.length > 0) {
					const total = this.formData.questions.reduce((sum, q) => sum + parseFloat(q.score), 0);
					this.formData.total_score = total;
				}
			},
			
			// 添加题目数据格式化方法
			formatQuestionData(question) {
				// 基础数据
				const formattedQuestion = {
					title: question.title || '',
					type: question.type,
					options: question.options || [],
					explanation: question.explanation || '',
					score: Number(question.score) || 5,
					media_files: question.media_files || []
				};
				
				// 根据题目类型处理正确答案
				if (question.type === 'single') {
					// 单选题：使用0-based索引
					formattedQuestion.correct_option = Number(question.correct_option);
					formattedQuestion.correct_options = [];
				} else if (question.type === 'multiple') {
					// 多选题：使用0-based索引数组
					formattedQuestion.correct_options = Array.isArray(question.correct_options) ? 
						question.correct_options.map(Number) : [];
					delete formattedQuestion.correct_option;
				} else if (question.type === 'judge') {
					// 判断题：使用布尔值
					formattedQuestion.correct_option = Boolean(question.correct_option);
					formattedQuestion.correct_options = [];
				}
				
				return formattedQuestion;
			},
			
			// 修改提交表单方法
			async submitForm() {
				// 表单验证
				if (!this.formData.title.trim()) {
					return this.showToast('请输入试卷标题');
				}
				if (!this.formData.description.trim()) {
					return this.showToast('请输入试卷描述');
				}
				if (!this.formData.time_limit || this.formData.time_limit <= 0) {
					return this.showToast('请输入有效的考试时间');
				}
				if (!this.formData.total_score || this.formData.total_score <= 0) {
					return this.showToast('请输入有效的试卷总分');
				}
				if (!this.formData.pass_score || this.formData.pass_score <= 0) {
					return this.showToast('请输入有效的及格分数');
				}
				if (this.formData.pass_score > this.formData.total_score) {
					return this.showToast('及格分数不能大于总分');
				}
				if (this.formData.questions.length === 0) {
					return this.showToast('请至少添加一道题目');
				}
				
				// 编辑模式下检查ID
				if (this.isEditMode && !this.examId) {
					console.error('编辑模式下考试ID为空');
					return this.showToast('考试ID无效，无法更新');
				}
				
				// 设置提交状态
				this.submitting = true;
				
				try {
					// 上传封面图片
					let coverFileID = '';
					if (this.formData.cover_image) {
						coverFileID = await this.uploadCoverImage();
					}
					
					// 格式化所有题目数据
					const formattedQuestions = this.formData.questions.map(q => this.formatQuestionData(q));
					
					// 准备提交的数据
					const submitData = {
						title: this.formData.title,
						description: this.formData.description,
						exam_type: this.formData.exam_type,
						time_limit: parseInt(this.formData.time_limit),
						pass_score: parseInt(this.formData.pass_score),
						total_score: parseInt(this.formData.total_score),
						questions: formattedQuestions, // 使用格式化后的题目数据
						cover_image: coverFileID,
						is_published: true,
						userId: this.getUserId(),
						token: this.getToken(),
						media_files: this.formData.media_files || []
					};
					
					// 如果是编辑模式，添加考试ID
					if (this.isEditMode) {
						submitData.examId = this.examId;
					}
					
					console.log('准备提交数据:', JSON.stringify(submitData));
					
					// 提交数据
					const examService = uniCloud.importObject('exam-service');
					const methodName = this.isEditMode ? 'updateExam' : 'uploadExamPaper';
					const res = await examService[methodName](submitData);
					
					if (res && res.code === 0) {
								uni.showModal({
									title: this.isEditMode ? '更新成功' : '提交成功',
									content: this.isEditMode ? '试卷已成功更新' : '试卷已成功上传',
									showCancel: false,
									success: () => {
										if (this.isEditMode) {
											try {
												uni.removeStorageSync('edit_exam_id');
											} catch (e) {
												console.error('清除本地存储ID失败', e);
											}
											uni.navigateBack();
										} else {
											this.resetForm();
										}
									}
								});
							} else {
						this.showToast((res && res.message) || '提交失败，请稍后重试');
					}
				} catch (error) {
					console.error('提交失败:', error);
					this.showToast('提交失败，请稍后重试');
				} finally {
					this.submitting = false;
				}
			},
			
			// 重置表单
			resetForm() {
				this.formData = {
					title: '',
					description: '',
					exam_type: 'knowledge',
					time_limit: 60,
					total_score: 100,
					pass_score: 60,
					cover_image: '',
					questions: [],
					media_files: [] // 添加整个试卷的顶层media_files字段
				};
				this.examTypeIndex = 0;
				this.uploadStatus.cover = false;
			},
			
			// 显示提示消息
			showToast(message) {
				uni.showToast({
					title: message,
					icon: 'none',
					duration: 2000
				});
			},
			
			// 获取用户ID
			getUserId() {
				// 尝试从本地存储获取用户信息
				try {
					const userInfoStr = uni.getStorageSync('userInfo');
					if (userInfoStr) {
						const userInfo = JSON.parse(userInfoStr);
						const userId = userInfo._id || userInfo.userId || userInfo.id || '';
						console.log('获取到用户ID:', userId);
						return userId;
					}
				} catch (e) {
					console.error('获取用户ID出错:', e);
				}
				return '';
			},
			
			// 获取token
			getToken() {
				// 尝试从本地存储获取token，按优先级尝试多种存储键
				try {
					// 首先尝试从用户信息中获取
					const userInfoStr = uni.getStorageSync('userInfo');
					if (userInfoStr) {
						const userInfo = JSON.parse(userInfoStr);
						if (userInfo.token) {
							console.log('从用户信息获取到token');
							return userInfo.token;
						}
					}
					
					// 按优先级尝试不同的token存储键
					const tokenKeys = ['user_token', 'uni_id_token', 'token'];
					for (const key of tokenKeys) {
						const token = uni.getStorageSync(key);
						if (token) {
							console.log(`从${key}获取到token`);
							return token;
						}
					}
				} catch (e) {
					console.error('获取token出错:', e);
				}
				return '';
			},
			
			// 修改加载试卷详情的方法
			async loadExamDetail() {
				// 检查考试ID是否有效
				if (!this.examId) {
					this.showToast('考试ID无效，无法加载');
					this.isEditMode = false;
					setTimeout(() => {
						uni.navigateBack();
					}, 1500);
					return;
				}
				
				uni.showLoading({
					title: '加载中...'
				});
				
				console.log('正在加载考试详情，ID:', this.examId);
				
				try {
					// 构建请求参数
					const requestData = {
						examId: this.examId  // 使用正确的参数名
					};
					
					// 添加额外调试信息
					console.log('详情查询参数:', JSON.stringify(requestData));
					
					const examService = uniCloud.importObject('exam-service');
					const res = await examService.getExamDetail(requestData);
					
							uni.hideLoading();
							
							console.log('获取考试详情返回:', res);
							
					if (res && res.code === 0) {
						const examData = res.data;
								
								// 填充表单数据
								this.formData = {
									title: examData.title || '',
									description: examData.description || '',
									exam_type: examData.exam_type || 'knowledge',
									time_limit: examData.time_limit || 60,
									total_score: examData.total_score || 100,
									pass_score: examData.pass_score || 60,
									cover_image: examData.cover_image || '',
									questions: examData.questions || [],
									media_files: examData.media_files || [] // 添加试卷整体的媒体文件
								};
								
								// 设置试卷类型索引
								this.setExamTypeIndex(examData.exam_type);
								
								// 如果有考题，把封面图片标记为已上传状态
								if (this.formData.cover_image) {
									this.uploadStatus.cover = true;
								}
								
								console.log('已加载考试详情:', this.formData);
							} else {
						console.error('获取考试详情失败:', res);
						this.showToast('获取考试详情失败: ' + (res?.message || '未知错误'));
								this.isEditMode = false;
								setTimeout(() => {
									uni.navigateBack();
								}, 1500);
							}
				} catch (error) {
					uni.hideLoading();
					console.error('加载考试详情出错:', error);
					this.showToast('系统错误，请稍后再试');
					this.isEditMode = false;
					setTimeout(() => {
						uni.navigateBack();
					}, 1500);
				}
			},
			
			// 预览媒体文件
			previewMedia(media) {
				if (media.type === 'image') {
					uni.previewImage({
						urls: [media.url],
						current: media.url
					});
				}
			},
			
			// 添加题目
			navigateToQuestionEdit() {
				// 将当前已添加的题目存入本地存储
				uni.setStorageSync('edit_questions', JSON.stringify(this.formData.questions));
				
				// 跳转到题目编辑页面
				uni.navigateTo({
					url: `/packageadmin/admin/question-edit?examId=${this.examId}&index=${this.formData.questions.length}`
				});
			},
			
			// 编辑现有题目
			editQuestion(index) {
				// 将当前已添加的题目存入本地存储
				uni.setStorageSync('edit_questions', JSON.stringify(this.formData.questions));
				
				// 跳转到题目编辑页面，传入题目索引
				uni.navigateTo({
					url: `/packageadmin/admin/question-edit?examId=${this.examId}&index=${index}`
				});
			},
			
			// 添加获取题目类型名称的方法
			getQuestionTypeName(type) {
				if (type === 'single') {
					return '单选题';
				} else if (type === 'multiple') {
					return '多选题';
				} else {
					return '判断题';
				}
			},
			
			// 处理视频加载错误
			handleVideoError(e) {
				console.error('视频加载错误:', e.detail);
				uni.showToast({
					title: '视频加载失败，请检查格式',
					icon: 'none'
				});
			},
		},
		onShow() {
			// 从本地存储获取编辑过的题目数据
			const questionsStr = uni.getStorageSync('edit_questions');
			if (questionsStr) {
				try {
					const questions = JSON.parse(questionsStr);
					if (Array.isArray(questions) && questions.length > 0) {
						this.formData.questions = questions;
						// 清除本地存储
						uni.removeStorageSync('edit_questions');
					}
				} catch (e) {
					console.error('解析题目数据失败', e);
				}
			}
		}
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		margin: 0;
		padding: 0;
		overflow-x: hidden;
	}
	
	.container {
		padding: 30rpx;
		min-height: 100vh;
		width: 100%;
		box-sizing: border-box;
		background-color: #f5f5f5;
		overflow-x: hidden;
	}
	
	.form-section {
		background-color: #FFFFFF;
		border-radius: 12rpx;
		padding: 30rpx;
		margin-bottom: 30rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
		width: 100%;
		box-sizing: border-box;
	}
	
	.section-title {
		font-size: 36rpx;
		font-weight: bold;
		margin-bottom: 20rpx;
		color: #333333;
		display: block;
		width: 100%;
		box-sizing: border-box;
	}
	
	.section-desc {
		font-size: 28rpx;
		color: #666666;
		margin-bottom: 40rpx;
		display: block;
		width: 100%;
		box-sizing: border-box;
	}
	
	.form-item {
		margin-bottom: 30rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.form-label {
		font-size: 28rpx;
		color: #333333;
		margin-bottom: 15rpx;
		display: block;
		width: 100%;
		box-sizing: border-box;
	}
	
	.required:after {
		content: ' *';
		color: #FF0000;
	}
	
	.form-input {
		background-color: #F8F8F8;
		padding: 20rpx;
		border-radius: 8rpx;
		font-size: 28rpx;
		width: 100% !important;
		box-sizing: border-box;
		color: #333333;
		display: block;
		max-width: 100%;
	}
	
	.text-right {
		text-align: right;
	}
	
	.textarea-container {
		background-color: #F8F8F8;
		border-radius: 8rpx;
		padding: 20rpx;
		box-sizing: border-box;
		width: 100%;
		max-width: 100%;
		overflow: hidden;
	}
	
	.form-textarea {
		width: 100% !important;
		height: 200rpx;
		font-size: 28rpx;
		color: #333333;
		box-sizing: border-box;
		max-width: 100%;
		display: block;
	}
	
	uni-textarea {
		width: 100%;
		max-width: 100%;
	}
	
	.form-picker {
		background-color: #F8F8F8;
		padding: 20rpx;
		border-radius: 8rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.picker-value {
		font-size: 28rpx;
		color: #333333;
		width: 100%;
		box-sizing: border-box;
	}
	
	.submit-section {
		padding: 20rpx 0;
		width: 100%;
		box-sizing: border-box;
	}
	
	.submit-btn {
		background-color: #007F4F;
		color: #FFFFFF;
		font-size: 32rpx;
		padding: 20rpx 0;
		border-radius: 8rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.submit-btn[disabled] {
		background-color: #CCCCCC;
		color: #FFFFFF;
	}
	
	.questions-section {
		margin-top: 30rpx;
		background-color: #FFFFFF;
		border-radius: 12rpx;
		padding: 30rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
		width: 100%;
		box-sizing: border-box;
	}
	
	.section-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.add-btn {
		font-size: 28rpx;
		color: #007F4F;
		padding: 10rpx 20rpx;
		border-radius: 6rpx;
		border: 1rpx solid #007F4F;
		background-color: transparent;
		line-height: 1.5;
		margin: 0;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		min-width: 180rpx;
		text-align: center;
	}
	
	.add-btn-hover {
		background-color: #f0f9f5;
	}
	
	.empty-tip {
		text-align: center;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.empty-text {
		font-size: 28rpx;
		color: #666666;
	}
	
	.question-list {
		margin-top: 20rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.question-item {
		background-color: #FFFFFF;
		border-radius: 8rpx;
		padding: 20rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 1rpx 5rpx rgba(0, 0, 0, 0.05);
		border: 1rpx solid #EEEEEE;
		width: 100%;
		box-sizing: border-box;
	}
	
	.question-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.question-number {
		font-size: 28rpx;
		color: #333333;
	}
	
	.question-type {
		font-size: 28rpx;
		color: #666666;
	}
	
	.question-score {
		font-size: 28rpx;
		color: #666666;
	}
	
	.question-title {
		font-size: 28rpx;
		color: #333333;
		margin-bottom: 10rpx;
		width: 100%;
		box-sizing: border-box;
		word-wrap: break-word;
	}
	
	.question-options {
		margin-bottom: 10rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.option-item {
		margin-bottom: 5rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.option-letter {
		font-size: 28rpx;
		color: #333333;
	}
	
	.option-content {
		font-size: 28rpx;
		color: #666666;
		word-wrap: break-word;
	}
	
	.option-correct {
		font-size: 28rpx;
		color: #007F4F;
		margin-left: 10rpx;
	}
	
	.question-judge {
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		width: 100%;
		box-sizing: border-box;
	}
	
	.judge-answer {
		font-size: 28rpx;
		color: #666666;
	}
	
	.question-actions {
		margin-top: 10rpx;
		display: flex;
		justify-content: flex-end;
		width: 100%;
		box-sizing: border-box;
	}
	
	.action-btn {
		font-size: 28rpx;
		color: #666666;
		padding: 6rpx 20rpx;
		border-radius: 6rpx;
		margin-left: 10rpx;
	}
	
	.edit-btn {
		border: 1rpx solid #007F4F;
		color: #007F4F;
	}
	
	.delete-btn {
		background-color: #FF5151;
		color: #FFFFFF;
	}
	
	/* 添加题目按钮 */
	.add-question-btn {
		background-color: #007F4F;
		color: #FFFFFF;
		padding: 10rpx 20rpx;
		border-radius: 6rpx;
		border: 1rpx solid #007F4F;
		line-height: 1.5;
		margin: 0;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		min-width: 180rpx;
		text-align: center;
	}
	
	.plus-icon {
		display: inline-block;
		font-size: 28rpx;
		margin-right: 4rpx;
	}
	
	/* 添加媒体文件预览样式 */
	.question-media {
		margin: 10rpx 0;
	}
	
	.media-preview {
		margin-bottom: 10rpx;
	}
	
	.media-image {
		width: 100%;
		height: 200rpx;
		border-radius: 8rpx;
	}
	
	.media-video {
		width: 100%;
		height: 300rpx;
		border-radius: 8rpx;
	}
</style>